import InfoModal from '@/pages/Task/components/InfoModal';
import mapping from './changeInfoKeyRenderMapping';
import { fetchOperateDetails } from './util';

// 变更详情 -----
const render = (value, record) => {
    const r = mapping[record.field];
    if (r) {
        return r(value);
    }
    return !value && value !== 0 ? '' : value;
};

const columns = [
    {
        title: '字段名称',
        dataIndex: 'fieldName',
        width: 120
    },
    {
        title: '变更前',
        dataIndex: 'beforeVal',
        width: 340,
        render
    },
    {
        title: '变更后',
        dataIndex: 'afterVal',
        width: 340,
        render
    }
];
export const showChangeInfoModal = async (id, operateRecordId) => {
    let dataSource = await fetchOperateDetails(id, operateRecordId);
    dataSource = dataSource.map((item, index) => ({ id: index, ...item }));
    return InfoModal.showTableModal({ columns, dataSource, title: '变更详情', width: 840 });
};
